local skel = fk.CreateSkill {
  name = "rmt__xixi",
}

Fk:loadTranslationTable{
  ["rmt__xixi"] = "犀嬉",
  [":rmt__xixi"] = "出牌阶段限一次，你可令一名其他角色回复1点体力，视为对其使用伤害基数为5、被【杀】响应后伤害-1的【决斗】，"..
  "你与其均可摸或弃两张牌视为打出【杀】响应之，均选择摸牌后，均不能再响应。",

  ["#rmt__xixi"] = "犀嬉：令一名其他角色回复体力，视为对其用【决斗】！",
  ["#rmt__xixi-choice"] = "犀嬉：你可以摸两张牌或弃置两张牌视为响应此【决斗】",
  ["#rmt__xixi_trigger"] = "犀嬉",
  ["rmt__xixi_discard"] = "弃两张牌",

  ["$rmt__xixi1"]= "吾既身受宠遇，敢不为君分忧？",
  ["$rmt__xixi2"]= "君既赌输，理当再脱一件！",
  ["$rmt__xixi3"]= "以侯归第，终败于其！",
  ["$rmt__xixi4"]= "君若如此，让我如何见人？",
  ["$rmt__xixi5"]= "望陛下听臣忠言，勿信资等无知之论！",
  ["$rmt__xixi6"]= "此亦久矣，岂能复几！",
  ["$rmt__xixi7"]= "臣得君上垂青，已是此生之幸。",
  ["$rmt__xixi8"]= "前朝王莽之乱，可为今史之鉴。",
}

skel:addEffect("active", {
  anim_type = "drawcard",
  prompt = "#rmt__xixi",
  mute = true,
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, player, to_select, selected, selected_cards)
    return #selected == 0 and to_select ~= player
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(skel.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local to = effect.tos[1]
    player:broadcastSkillInvoke(skel.name, 1)
    room:notifySkillInvoked(player, skel.name, "offensive")
    room:recover {
      num = 1,
      skillName = skel.name,
      who = to,
      recoverBy = player,
    }
    if player.dead or to.dead then return end
    local card = Fk:cloneCard("duel")
    card.skillName = skel.name
    if player:prohibitUse(card) or player:isProhibited(to, card) then return end
    room:useCard{
      from = player,
      tos = {to},
      card = card,
      additionalDamage = 4,
      extra_data = { rmt__xixi_tos = {player.id, to.id} }}
  end,
})

skel:addEffect(fk.AskForCardResponse, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    if target ~= player then return end
    if Exppattern:Parse(data.pattern):matchExp("slash|0|nosuit|none") and not player:prohibitResponse(Fk:cloneCard("slash")) then
      local effect = data.eventData
      return effect and effect.card and table.contains(effect.card.skillNames, skel.name)
      and effect.extra_data
      -- 限制只有自己和最初的目标才能如此响应……
      and table.contains(effect.extra_data.rmt__xixi_tos or {}, player.id)
      and effect.additionalDamage and effect.additionalDamage >= 0
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    local effect = data.eventData
    if effect == nil then return end
    effect.extra_data = effect.extra_data or {}
    effect.extra_data.rmt__xixiDraw = effect.extra_data.rmt__xixiDraw or {}
    local drawer = effect.extra_data.rmt__xixiDraw
    local choices = {"draw2"}
    if #table.filter(player:getCardIds("he"), function(id) return not player:prohibitDiscard(id) end) > 1 then
      table.insert(choices, "rmt__xixi_discard")
    end
    if #choices == 0 then return end
    table.insert(choices, "Cancel")
    local choice = room:askToChoice(player, {choices = choices, skill_name = skel.name, prompt = "#rmt__xixi-choice"})
    if choice == "Cancel" then return end
    if choice == "draw2" then
      player:broadcastSkillInvoke("rmt__xixi", table.random({2, 3}))
      player:drawCards(2, skel.name)
      table.insertIfNeed(drawer, player.id)
      if #drawer == 2 then
        effect.disresponsive = true
      end
    else
      player:broadcastSkillInvoke("rmt__xixi", table.random({4, 5}))
      room:askToDiscard(player, {
        min_num = 2,
        max_num = 2,
        include_equip = true,
        skill_name = skel.name,
        cancelable = false,
      })
    end
    local card = Fk:cloneCard("slash")
    card.skillName = skel.name
    data.result = {
      from = player,
      card = card,
    }
    return true
  end,
})

skel:addEffect(fk.CardResponding, {
  mute = true,
  is_delay_effect = true,
  can_trigger = function (self, event, target, player, data)
    if target ~= player then return end
    if data.card.trueName == "slash" then
      local effect = data.responseToEvent
      return effect and effect.card and table.contains(effect.card.skillNames, skel.name)
      and effect.additionalDamage and effect.additionalDamage >= 0
    end
  end,
  on_use = function (self, event, target, player, data)
    player:broadcastSkillInvoke(skel.name, table.random({6, 7, 8}))
    local effect = data.responseToEvent
    if effect == nil then return end
    effect.additionalDamage = effect.additionalDamage - 1
  end,
})

return skel
